using System;
using System.Collections.Generic;

namespace LannyPractiseCode
{
    /// <summary>
    /// 双重锁（线程安全的单例模式）
    /// </summary>
    public class Singleton3
    {
        public static Object obj = new Object();
        //01.创建了一个类型是本类对象的静态属性
        private static Singleton3 instance = null;
        //02.构造私有化
        private Singleton3()
        {
        }
        //03.提供外部访问的接口，返回当前类的对象
        public static Singleton3 getInstance()
        {
            if (instance == null)
            {
                lock (obj)
                {  //再次加锁，线程安全
                    if (instance == null)
                    {
                        instance = new Singleton3();
                    }
                }
            }
            return instance;
        }
    }
}